<template>
  <div class="home-box">
    <el-container style="height: 100%">
        <el-header>
            <span class="title">企业办公自动化系统</span>
            <span class="adminPic">
                <el-menu
                    class="el-menu-demo"
                    mode="horizontal"
                    background-color="">
                    <el-submenu index="2">
                        <template slot="title">
                            <span style="margin-right:24px">
                            <el-badge :count="1">
                                <img :src="userAvatar" width="40" height="40">
                            </el-badge>
                            </span>
                        </template>
                        <el-menu-item index="2-1" @click="logout">
                            &nbsp;<logout theme="outline" size="18" fill="#4a4a4a" class="logout-icon"/>
                            &nbsp;
                            <span class="home-user">退出登录</span>
                        </el-menu-item>
                        <el-menu-item index="2-2" @click="goSelfCenter()">
                            <i class="el-icon-user"></i>
                            <span>个人中心</span>
                        </el-menu-item>
                        <el-menu-item index="2-3" @click="setting()">
                            <i class="el-icon-s-tools"></i>
                            <span>设置中心</span>
                        </el-menu-item>
                    </el-submenu>
                </el-menu>
            </span>
        </el-header>
        <el-container>
            <el-aside style="width:200px;height:100%">
                <el-menu
                    default-active="1"
                    unique-opened
                    router
                    class="el-menu-vertical-demo"
                    background-color="rgb(40, 56, 72)"
                    text-color="#fff"
                    active-text-color="#ffd04b">
                    <template v-for="(item,i) in menusForm">
                        <!-- index 为顺序 -->
                        <el-submenu :index="item.menuSort.toString()" :key="i">
                            <template slot="title">
                                <i :class="item.menuIcon"></i>
                                <span>{{item.menuName}}</span>
                            </template>
                            <el-menu-item-group>
                                <!-- index 为跳转的路径 -->
                                <el-menu-item v-for="(child,j) in item.childList" :index="child.skipPath" :key="j">
                                    <i :class="child.menuIcon"></i>
                                    {{child.menuName}}
                                </el-menu-item>
                            </el-menu-item-group>
                        </el-submenu>
                    </template>
                </el-menu>
            </el-aside>
            <el-main>
                <router-view/>
            </el-main>
        </el-container>
      <!-- <el-footer>Footer</el-footer> -->
    </el-container>
  </div>
</template>

<script>
import {Logout , Dollar} from '@icon-park/vue';
export default {
    components:{
        Logout,
        Dollar
    },
    created(){
        this.currUser = JSON.parse(sessionStorage.getItem("user"));
    },
    data(){
        return{
            userAvatar:require('../assets/images/di.jpg'),
            baseUrl:'http://localhost:8088/oa-system',
            menusForm:[],
            currUser:{}
        }
    },
    created(){
        this.currUser = JSON.parse(sessionStorage.getItem("user"));
        this.getMenus();
    },
    methods:{
        //获取菜单
        getMenus(){
            this.$http.get("/menuInfo/getMenus?userId="+this.currUser.userId).then((res)=>{
                // console.log(res);
                if(res.code === 200){
                    let dataArr = res.data;
                    // 排序处理
                    dataArr.sort((a,b)=>{return a.menuSort - b.menuSort});
                    this.menusForm = dataArr;
                }else{
                    this.$message.warning("获取菜单失败,请联系管理员!!!");
                }
            }).catch((err)=>{
                this.$message.error("获取菜单失败,请联系管理员!!!");
            });
        },
        //退出
        logout(){
            this.$confirm('确定退出? 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
                }).then(() => {
                    sessionStorage.clear();
                    this.$router.push("/");
                }).catch(() => {});
        },
        goSelfCenter(){
            this.$router.push("/selfInfo");
        },
        //设置
        setting(){
            this.$router.push("/addMenu");
        }
    }
};
</script>

<style scoped>
.home-box{
    width: 100%;
    height: 100%;
}
.el-header {
  color: rgb(59, 84, 113);
  height: 60px;
  /* background-image: linear-gradient(160deg, #0093e9 0%, #80d0c7 100%); */
  display: flex;
  justify-content: space-between;
}
/* .el-footer {
  color: #333;
  text-align: center;
  line-height: 60px;
  background-image: linear-gradient(160deg, #0093e9 0%, #80d0c7 100%);
} */

.el-aside {
  background-color:rgb(40, 56, 72);
}

.el-main {
  /* height: 100%; */
  background-color: #e9eef3;
}
.home-box .title{
    width: 100%;
    height: 100%;
    font-size: 18px;
    line-height: 60px;
}
.home-box .home-user{
  margin-left: -10px;
}
.home-box .logout-icon{
      cursor: pointer;
}
.el-menu-item:hover{
    background-color: grey;
}
</style>
